const sequelize = require('../connection');
const { DataTypes } = require("sequelize");
//
const moment = require('moment');
// import { DataTypes } from "sequelize";
// import { sequelize  } from '../connection';
// console.log("sequelize", sequelize);

const TodoList = sequelize.define(
    "todo_list",
    {
        id: {
            type: DataTypes.INTEGER,
            primaryKey: true,
            allowNull: true,
            autoIncrement: true
        },
        task_name: {
            type: DataTypes.STRING,
            allowNull: false
        },
        task_content: {
            type: DataTypes.STRING,
            allowNull: false
        },
        // 创建时间
        create_time: {
            type: DataTypes.DATE,
            defaultValue: new Date(),
            get() {
                return moment(this.getDataValue('create_time')).format('YYYY-MM-DD HH:mm:ss');
            }
        },
        complete_time: {
            type: DataTypes.DATE,
            defaultValue: new Date(),
            // get() {
            //     return moment(this.getDataValue('create_time')).format('YYYY-MM-DD HH:mm:ss');
            // }
        },
        status:{
            type: DataTypes.INTEGER,
            allowNull: false,
            defaultValue: '1',
            comment: "1 0",
        },
        img: {
            type: DataTypes.STRING,
            allowNull: false
        },
    }, {
        // timestamps: true,
        // createdAt: false,
        timestamps: false,
        tableName: 'todo_list'
    })

// Article.sync()


// !(async function () {
//     const sange = await News.create({
//             "title":"company news - new policy",
//             "content":"new policy new policynew policynew policynew policynew policynew policy",
//             "category_id":2,
//             "created_by": 2
//         });
//     console.log(sange)
// })()

module.exports = TodoList;

// const test = () => {
//     return  new Promise((resolve, reject) => {
//         const res = News.created({
//             "title":"company news - new policy",
//             "content":"new policy new policynew policynew policynew policynew policynew policy"
//         });
//         resolve(res);
//     })
//
// }
//
// console.log(test());

